<%-- 
  - Author: Abed Yaseen
  - Date: 02-Jan-2012
  - Copyright Notice: TRAKHEES
  - Description: show.jsp
 --%>
<%@ include file="/WEB-INF/view/include.jsp"%>

<div id="search_container">
      <div class="t_search_heading"><spring:message code="label.app_search" /></div>
      <form>
       <div class="t_search-left">
        <label class="label-search"><spring:message code="label.reference_no" /></label>
        <input name="referenceNo" id="referenceNo" type="text" class="t_form-fld" />
        <div class="clear"></div>
        <label class="label-search"><spring:message code="label.date_from" /></label>
        <input name="dateFrom" id="dateFrom" type="text" id="dateFrom" class="t_calendar-fld" />
        
        
        <div class="clear"></div>
      	</div>
      	<div class="t_search-right">
      	<div class="clear"></div>
        <label class="label-search"><spring:message code="label.service_name" /></label>
        <input name="serviceName" id="serviceName" type="text" class="t_form-fld" />
        <div class="clear"></div>
        <label class="label-search"><spring:message code="label.label_to" /></label>
        <input name="dateTo" id="dateTo" type="text"  id="dateTo" class="t_calendar-fld" />
        <div class="clear"></div>
        <label class="label-search"><spring:message code="label.filter_by" /></label>
        <select id="status" name="status">
				<c:forEach var="item" items="${StatusListAll}">
					<option value="${item.statusCode}"><spring:message code="CLDOS_APPLICATION_STATUS_${item.statusCode}" /></option>
				</c:forEach>
		</select>
       </div>
      
      <div class="t_search_btns">
	      			 <button type="button" onclick="gridReload()" id="submitButton" class="button_small" ><spring:message code="button.search" /></button>
	      			<button  type="reset" class="button_small" ><spring:message code="button.reset" /></button>
      </div>
     </form> 
 </div>
 <BR />
 <div id="TasksGrid" style="width: 718px;">
	 <table id="listApplications"></table> 
	 <div id="pager"></div>
 </div>
 <script>
	jQuery(document).ready(function() {
	
					$(".topnav").accordion({
						accordion:false,
						speed: 500,
						closedSign: '<img src=\'resources/images/common/close.jpg\' />',
						openedSign: '<img src=\'resources/images/common/open.jpg\' />'
					});
					
					$(document).keypress(function(e) {
						if (e.keyCode == 13) {
							gridReload();
						}
					});
	
					$('#listApplications').jqGrid({
									datatype :'json',
									url		 :'${pageContext.request.contextPath}/admin/general/all/request/displayAllAppRequests.json',
									colNames : [ '<spring:message code="grid.columnname.no" />',
										  		 '<spring:message code="grid.columnname.service_name" />',
										  		 '<spring:message code="grid.columnname.reference_no" />',
										  		 '<spring:message code="grid.columnname.sent_on" />',
										  		 '<spring:message code="grid.columnname.status" />',
										  		 '<spring:message code="grid.columnname.view" />' ],
										  		
									
									colModel : [
									  {name:'id',index:'id', width:55, sortable:false}, 
									  {name:'servicename',index:'servicename', width:150, align:"left",sortable : true}, 
									  {name:'reference',index:'reference', width:80,sortable : true}, 
									  {name:'senton',index:'senton', width:100, sortable : true}, 
									  {name:'status',index:'status', width:150, sortable : true},
									  {name:'action',index:'action', width:150, align:"center", sortable : true}
									
									 ],
									height:300,
									rowNum: 15,
									autowidth: true, 
									viewrecords: true,
									rowList:[10,20,30], 
									pager: jQuery('#pager'), 
									sortname: 'id', 
									viewrecords: true, 
									sortorder: "asc",
									hidegrid: false,
									caption : '<spring:message code="menu.label.app.requests" />'
									<c:if test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
									, direction:'rtl'
									</c:if>									
								});
					
			$( "#dateFrom,#dateTo" ).datepicker({
				showOn: "button",
				buttonImage: "resources/images/calender.jpg",
				dateFormat : 'dd/mm/yy',
				buttonImageOnly: true,
				changeMonth:true,
				changeYear:true,
				minDate: new Date(1900,1 - 1 ,1),
				yearRange:'c-50:c+10'
			});
			
			$('select#EmployeeType').selectmenu({
					style:'dropdown', 
					menuWidth: 240,
					format: addressFormatting
				});	

	});
	 var addressFormatting = function(text){
				var newText = text;
				//array of find replaces
				var findreps = [
					{find:/^([^\-]+) \- /g, rep: '<span class="ui-selectmenu-item-header">$1</span>'},
					{find:/([^\|><]+) \| /g, rep: '<span class="ui-selectmenu-item-content">$1</span>'},
					{find:/([^\|><\(\)]+) (\()/g, rep: '<span class="ui-selectmenu-item-content">$1</span>$2'},
					{find:/([^\|><\(\)]+)$/g, rep: '<span class="ui-selectmenu-item-content">$1</span>'},
					{find:/(\([^\|><]+\))$/g, rep: '<span class="ui-selectmenu-item-footer">$1</span>'}
				];
				
				for(var i in findreps){
					newText = newText.replace(findreps[i].find, findreps[i].rep);
				}
				return newText;
	}
	
	function gridReload(){
	
		 var referenceNo = jQuery("#referenceNo").val();
		 var dateFrom = jQuery("#dateFrom").val(); 
		 var serviceName = jQuery("#serviceName").val();
		 var dateTo = jQuery("#dateTo").val();
		 var status = jQuery("#status").val(); 
		 
		 jQuery("#listApplications").jqGrid('setGridParam',
		 							{url:"${pageContext.request.contextPath}/admin/general/all/request/displayAllAppRequests.json?referenceNo="
		 								+referenceNo
		 								+"&serviceName="+serviceName
		 								+"&dateFrom="+dateFrom
		 								+"&dateTo="+dateTo
		 								+"&status="+status,page:1}
		 							   ).trigger("reloadGrid");
    }
		
</script>